<?php

namespace app\supplier\controller\stall;

use app\Request;
use app\supplier\controller\Controller;
use app\supplier\model\stall\Category as CategoryModel;

/**
 * 商品分类
 */
class Category extends Controller
{

    /**
     * 商品分类管理
     */
    public function adminindex(Request $request)
    {
        $id = $request->param('id') ?? 0;
        $model = new CategoryModel;
        $list = $model->getCategorytree($id, $this->getSupplierId());
        return $this->renderSuccess('', compact('list'));
    }

    /**
     * @Exp 显示分类
     * @Auth Mr.Z
     */
    public function productcate(Request $request)
    {
        $id = $request->param('id') ?? 0;
        $model = new CategoryModel;
        $list = $model->getStallCateTree($id, $this->getSupplierId());
        return $this->renderSuccess('', compact('list'));
    }

    /**
     * 权限状态
     */
    public function status()
    {
        $postData = $this->request->post();
        $model = new CategoryModel();
        if ($model->setStatus($postData, $postData['id'] ?? 0)) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }

}
